/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package vsnds;

  import org.apache.xmlrpc.server.PropertyHandlerMapping;
  import org.apache.xmlrpc.server.XmlRpcServer;
  import org.apache.xmlrpc.server.XmlRpcServerConfigImpl;
  import org.apache.xmlrpc.webserver.WebServer;

/**
 *
 * @author rexcze
 */
public class XmlRpc implements ObsluhaPozadavku {

    private static final int port = 8080;

    WebServer webServer = null;

    public void XmlRpc() throws Exception {

    //tady asi neco chybi, ale nevim co  FIX
    }

    public void start(Vykonavatel vykonavatel) {
        try {
          webServer = new WebServer(port);

          XmlRpcServer xmlRpcServer = webServer.getXmlRpcServer();

          PropertyHandlerMapping phm = new PropertyHandlerMapping();

          //prirazeni objektu s metodami, ktere se daji vzdalene volat
          RpcFunkce.vykonavatel = vykonavatel;
          phm.addHandler("Funkce" , RpcFunkce.class);
          xmlRpcServer.setHandlerMapping(phm);

          //konfigurace serveru FIX
          XmlRpcServerConfigImpl serverConfig =
              (XmlRpcServerConfigImpl) xmlRpcServer.getConfig();
          serverConfig.setEnabledForExtensions(true);
          serverConfig.setContentLengthOptional(false);
            webServer.start();
        } catch (Exception ex) {
            //FIX vytvoreni vyjimky
            System.out.println("XMLRPC: chyba start "+webServer.toString());
        }
    }

    public void stop() {
        try {
            webServer.shutdown();
        } catch (Exception ex) {
            //FIX vytvoreni vyjimky
            System.out.println("XMLRCP: chyba stop");
        }
    }

}
